<!-- eslint-disable vue/valid-template-root -->
<template>
  <template v-for="(item, index) in props.menuData">
    <el-menu-item
      v-if="!item.children || item.children.length == 0"
      :key="`${props.index}-${item.meta.id}`"
      :index="`${props.index}-${item.meta.id}`"
      @click="handleClick(item,'`${props.index}-${item.meta.id}`')"
    >
      <el-icon>
        <component :is="item.meta.icon" />
      </el-icon>
      <span>{{ item.meta.name }}</span>
    </el-menu-item>

    <el-sub-menu
      v-else
      :key="`${props.index}-${item.meta.id}`"
      :index="`${props.index}-${item.meta.id}`"
    >
      <template #title>
        <el-icon>
          <component :is="item.meta.icon" />
        </el-icon>
        <span>{{ item.meta.name }}</span>
      </template>
      <tree-menu
        :menu-data="item.children"
        :index="`${props.index}-${item.meta.id}`"
      />
    </el-sub-menu>

  </template>

</template>
<script setup>
import { useRouter } from 'vue-router'
import { reactive, computed } from 'vue'
import { useStore } from 'vuex'

// eslint-disable-next-line no-undef, no-unused-vars
const props = defineProps(['menuData', 'index'])

const router = useRouter()

// eslint-disable-next-line no-undef, no-unused-vars
const store = useStore()

// eslint-disable-next-line no-unused-vars
const handleClick = (item, active) => {
  store.commit('addMeun', item.meta)
  store.commit('updateMenuActive', active)
  router.push(item.meta.path)
}

</script>
